//
//  BaseImageView.m
//  礼物说
//
//  Created by dllo on 16/5/4.
//  Copyright © 2016年 sunzhichao. All rights reserved.
//

#import "BaseImageView.h"

@implementation BaseImageView

- (instancetype)initWithImage:(UIImage *)image
{
    self = [super initWithImage:image];
    if (self) {
        
        [self createImgViews];
    }
    return self;
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"night" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [super dealloc];
}
- (void)createImgViews{
    
    
    BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNight"];
    
    if (result == YES) {
        
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.7;
        
        
        
        
    }else{
        
        self.alpha = 1;
        
    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nightAction:) name:@"night" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayAction:) name:@"day" object:nil];
    
    
    
}
- (void)nightAction:(NSNotification *)notification {
    
    self.backgroundColor = [UIColor blackColor];
    
    self.alpha = 0.1;
    
    
    
}

- (void)dayAction:(NSNotification *)notification {
    
    NSLog(@"日间模式开启成功");
    
    
    self.alpha = 1;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
